package com;

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * Created by hasee on 2015-09-24.
 */
public class IntroCanvas extends Canvas {
    private Color pink = new Color(255, 200, 200);
    private Color blue = new Color(150, 200, 255);
    private int w;

    private static final String title = "Scrabblet";
    private static final String name =
            "Copyright 1999 - Patrick Naughton";
    private static final String book =
            "Chapter 31 from 'Java: The Complete Reference'";
    private Font namefont, titlefont, bookfont;

    IntroCanvas() {
        Color yellow = new Color(250, 220, 100);
        setBackground(yellow);
        titlefont = new Font("SansSerif", Font.BOLD, 58);
        namefont = new Font("SansSerif", Font.BOLD, 18);
        bookfont = new Font("SansSerif", Font.PLAIN, 12);
        addMouseListener(new MyMouseAdapter());
    }

    private void d(Graphics g, String s, Color c, Font f, int y,
                   int off) {
        g.setFont(f);
        FontMetrics fm = g.getFontMetrics();
        g.setColor(c);
        g.drawString(s, (w - fm.stringWidth(s)) / 2 + off, y + off);
    }
    public void paint(Graphics g) {
        Dimension d = getSize();
        w = d.width;
        int h = d.height;
        g.setColor(blue);
        int edge = 16;
        g.fill3DRect(edge, edge, w - 2 * edge, h - 2 * edge, true);
        d(g, title, Color.black, titlefont, h / 2, 1);
        d(g, title, Color.white, titlefont, h / 2, -1);
        d(g, title, pink, titlefont, h / 2, 0);
        d(g, name, Color.black, namefont, h * 3 / 4, 0);
        d(g, book, Color.black, bookfont, h * 7 / 8, 0);
    }

    private class MyMouseAdapter implements MouseListener {
        public void mouseClicked(MouseEvent e) {

        }

        public void mousePressed(MouseEvent e) {
            getParent().setVisible(true);
        }

        public void mouseReleased(MouseEvent e) {

        }

        public void mouseEntered(MouseEvent e) {

        }

        public void mouseExited(MouseEvent e) {

        }
    }
}
